﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web.UI;
using WinnerCMS.BLL;
using WinnerCMS.BLL.PageFactory;
using WinnerCMS.BLL.PageFactory.TagModule;
using WinnerCMS.Common;
using WinnerCMS.Model;

namespace WinnerCMS.WebFactory
{
    public class ShopIndex : PublicPage
    {
        protected Category model;
        #region 重写事件
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Page_Load(object sender, System.EventArgs e)
        {
            this.model = CategoryManage.GetInfo(CategoryId);

            if (this.model == null)
                Response.Close();
        }

        #region 重写Render
        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder winner = new StringBuilder();
            using (TextWriter tempWriter = new StringWriter())
            {
                base.Render(new HtmlTextWriter(tempWriter));
                winner.Append(tempWriter.ToString());
            }
             
            IList<string> matchresult;
      
             
 
            matchresult = TagEngine.TagCollection(winner.ToString(), "Slide");
            foreach (string nextmatch in matchresult)
            {
                winner.Replace(nextmatch, PageCommon.Slide(winner.ToString()));
            }
             
            if (Request["Method"] != null)
            {
                string Path = StaticFilePath.CategoryUrl(this.model, 1);
                new FileIO().WriterFile(HttpServer.MapPath(Path), winner.ToString());
            }
            else
            {
                writer.Write(winner.ToString());
            }
        }
        #endregion
    }
}